<template>
  <a-modal
    :title="'会员卡号规则'"
    :width="640"
    :visible="visible"
    :confirmLoading="loading"
    @ok="
      () => {
        $emit('ok')
      }
    "
    @cancel="
      () => {
        $emit('cancel')
      }
    "
  >
    <a-spin :spinning="loading">
      <a-form :form="form" v-bind="formLayout">
        <a-form-item v-show="false" label="ID">
          <a-input v-decorator="['id']" disabled />
        </a-form-item>
        <a-form-item label="起始卡号">
          <a-input
            v-decorator="['name', { rules: [{ required: true, message: '请输入起始卡号' }] }]"
            placeholder="起始卡号"
          />
        </a-form-item>
        <a-form-item label="规则">
          <a-checkbox-group v-decorator="['type', { initialValue: [] }]">
            <a-row>
              <a-col :span="24">
                <a-checkbox value="2"> 跳过尾号4 </a-checkbox>
              </a-col>
              <a-col :span="24">
                <a-checkbox value="remark"> 跳过尾号7 </a-checkbox>
              </a-col>
            </a-row>
          </a-checkbox-group>
        </a-form-item>
        <a-form-item label="已发卡号至">
          <a-input
            v-decorator="['name', { rules: [{ initialValue:'尚未发卡' }] }]"
            placeholder="尚未发卡"
            disabled
          />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>
    
    <script>
import pick from 'lodash.pick'
// 表单字段
const fields = ['name', 'status', 'desc', 'id']

export default {
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
    loading: {
      type: Boolean,
      default: () => false,
    },
    model: {
      type: Object,
      default: () => null,
    },
    // eslint-disable-next-line vue/require-prop-types
    option: {
      type: [],
      default: () => null,
    },
  },
  data() {
    this.formLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 13 },
      },
    }
    return {
      form: this.$form.createForm(this),
    }
  },

  created() {
    // 防止表单未注册
    fields.forEach((v) => this.form.getFieldDecorator(v))
    // 当 model 发生改变时，为表单设置值
    this.$watch('model', () => {
      this.model && this.form.setFieldsValue(pick(this.model, fields))
    })
  },
}
</script>